<?php
require_once("../config.php"); 
require_once("../model/DB.php");
require_once("../model/User.php");
require_once("../model/Class.php");

$class = Classes::getClassById($_POST['Class']);

if($class['teacher_id']){
	if($class['teacher_id']!=$_POST['id']){
		echo "class";
		return false;
	}
}

if($_POST['id']!=0){
	if(User::edit($_POST['id'],$_POST['name'],$_POST['password'],$_POST['realname'],$_POST['contact'])){
		echo "saved";
		Classes::removeTeacher($_POST['id']);
		Classes::editTeacher($_POST['Class'],$_POST['id']);
	}	
}
else{
	if(User::add($_POST['name'],$_POST['password'],$_POST['realname'],$_POST['contact'],'teacher')){
		echo "added";
		$last = User::getLastId();
		
		Classes::editTeacher($_POST['Class'],$last['id']);
	}
}


?>